package Pre.Work;

import java.util.Objects;
import java.util.Vector;

public class Exam04 {
    private String name;

    private String garden;
    private int age;
    private double score;

    public Exam04(String name, String garden, int age, double score) {
        this.name = name;
        this.garden = garden;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGarden() {
        return garden;
    }

    public void setGarden(String garden) {
        this.garden = garden;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Exam04{" +
                "姓名='" + name + '\'' +
                ", 性别='" + garden + '\'' +
                ", 年龄=" + age +
                ", 成绩=" + score +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Exam04 exam04 = (Exam04) o;
        return age == exam04.age && Double.compare(score, exam04.score) == 0 && Objects.equals(name, exam04.name) && Objects.equals(garden, exam04.garden);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, garden, age, score);
    }
}
class Test02{
    public static void main(String[] args) {
        Vector vector = new Vector();
        vector.add(new Exam04("zcj", "男", 20, 88.8));
        vector.add(new Exam04("abc", "女", 18, 648));
        vector.add(new Exam04("ghx", "男", 24, 188));
        vector.add(new Exam04("wxy", "女", 35, 98));
        vector.add(new Exam04("wyn", "男", 12, 328));
        vector.add(new Exam04("zyn", "女", 36, 30));

        System.out.println("符合成绩范围的学生有：" + StudnetCount(vector, 30, 500) + "人");
    }

    public static Object StudnetCount(Vector vector,double num1,double num2){
        for (int i = 0; i < vector.size() - 1; i++) {
            for (int j = 0; j < vector.size() - 1 - i; j++) {
                Exam04 stu1 = (Exam04) vector.get(j);
                Exam04 stu2 = (Exam04) vector.get(j + 1);
                if (stu1.getScore() < stu2.getScore()){
                    vector.set(j,stu2);
                    vector.set(j + 1,stu1);
                }
            }
        }
        int count = 0;
        for (int i = 0; i <vector.size() ; i++) {
            Exam04 students = (Exam04) vector.get(i);
            if (students.getScore() > num1 && students.getScore() < num2){
                System.out.println(students);
                count ++;
            }
        }
        return count;
    }
}
